package com.c2rusthub.service.service;

import com.c2rusthub.service.mapper.TranslatedTaskMapper;
import com.c2rusthub.service.model.TranslatedTask;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TranslatedService {

    @Autowired
    private TranslatedTaskMapper translatedTaskMapper;

    // 根据 cUrl 查询已完成的转译任务列表
    public List<TranslatedTask> getTranslatedTasksByCUrl(String cUrl) {
        return translatedTaskMapper.findTranslatedTasksByCUrl(cUrl);
    }

    // 根据 id 查询已完成的转译任务详情
    public TranslatedTask getTranslatedTaskById(int id) {
        return translatedTaskMapper.findTranslatedTaskById(id);
    }

    public int getCompletedTaskCount() {
        return translatedTaskMapper.getCompletedTaskCount();
    }

    /**
     * 查询 likes 数前十的数据
     *
     * @return likes 前十的数据列表
     */
    public List<TranslatedTask> getTop10ByLikes() {
        return translatedTaskMapper.getTop10ByLikes();
    }

    /**
     * 点赞或点踩任务
     *
     * @param id     任务ID
     * @param action 操作类型 (like/diss)
     */
    public void likeOrDiss(Integer id, String action) {
        if ("like".equals(action)) {
            translatedTaskMapper.incrementLikes(id);
        } else if ("diss".equals(action)) {
            translatedTaskMapper.incrementDiss(id);
        }
    }

    public void insertTranslatedTask(TranslatedTask translatedTask) {
      translatedTaskMapper.insertTranslatedTask(translatedTask);
    }
}
